package com.engine4cloud.tdf.supervision.controller.web;

import cn.hutool.core.collection.CollUtil;
import com.engine4cloud.tdf.common.core.util.R;
import com.engine4cloud.tdf.common.log.annotation.SysLog;
import com.engine4cloud.tdf.supervision.dto.create.OutApplicationSettingCreateDTO;
import com.engine4cloud.tdf.supervision.dto.result.OutApplicationSettingResultDTO;
import com.engine4cloud.tdf.supervision.dto.update.OutApplicationSettingUpdateDTO;
import com.engine4cloud.tdf.supervision.service.OutApplicationSettingService;
import jakarta.validation.Valid;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import org.springframework.http.HttpHeaders;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 外出申请配置表
 *
 * @author wenjie
 * @date 2024-09-24 15:52:53
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/web/out/setting")
@Tag(description = "outApplicationSetting", name = "外出申请配置管理-web")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class OutApplicationSettingWebController {

    private final OutApplicationSettingService outApplicationSettingService;

    /**
     * 获取最新配置表
     *
     * @return R
     */
    @Operation(summary = "获取最新配置表", description = "获取最新配置表")
    @GetMapping("/first")
    public R<OutApplicationSettingResultDTO> findFirst() {
        return R.ok(outApplicationSettingService.findFirst());
    }

    /**
     * 新增外出申请配
     *
     * @param dto 外出申请配置
     * @return R
     */
    @Operation(summary = "新增外出申请配置", description = "新增外出申请配置")
    @SysLog("新增外出申请配置")
    @PostMapping
    @PreAuthorize("@pms.hasPermission('out_setting_add')")
    public R<Boolean> create(@Valid @RequestBody OutApplicationSettingCreateDTO dto) {
        return R.ok(outApplicationSettingService.create(dto));
    }

    /**
     * 修改外出申请配置
     *
     * @param dto 外出申请配置
     * @return R
     */
    @Operation(summary = "修改外出申请配置", description = "修改外出申请配置")
    @SysLog("修改外出申请配置")
    @PutMapping
    @PreAuthorize("@pms.hasPermission('out_setting_edit')")
    public R<Boolean> update(@Valid @RequestBody OutApplicationSettingUpdateDTO dto) {
        return R.ok(outApplicationSettingService.update(dto));
    }

    /**
     * 通过id删除外出申请配置
     *
     * @param ids id列表
     * @return R
     */
    @Operation(summary = "通过id删除外出申请配置", description = "通过id删除外出申请配置")
    @SysLog("通过id删除外出申请配置")
    @DeleteMapping
    @PreAuthorize("@pms.hasPermission('out_setting_del')")
    public R<Boolean> removeById(@RequestBody Long[] ids) {
        return R.ok(outApplicationSettingService.removeBatchByIds(CollUtil.toList(ids)));
    }
}